<?php

namespace IDock\Insurance\YAIC\Request;

use IDock\Insurance\YAIC\Response\UploadFileResponse;
use IDock\Visitor\UploadFileVisitor;

class UploadFileRequest extends AllYAICRequest
{
    protected $route = '';

    protected $response = UploadFileResponse::class;

    protected $urlTip = '影像上传';

    protected $inLog = true;

    public $transCode = 'B25';

    /*** @var  UploadFileVisitor $visitor */
    protected $visitor;

    protected $inquiryNo;


    public function generate(): array
    {

        $file = $this->visitor->fileList[0] ?? [];
        $url = $file['url'] ?? '';
        if(!file_get_contents($url)){
            throw new \Exception("图片不能为空");
        }
        $urlArr = explode('/',$url);
        $arr = [
            'bussNo' => $this->visitor->argc['uploadImageNo'] ?? '',
            'userCode' => $this->visitor->argc['userCode'] ?? '0251011010000',//userCode
            'comCode' => $this->visitor->argc['comCode'] ?? '10094454',//comCode
            'file' => base64_encode(file_get_contents($file['url'])),
            'fileName' => end($urlArr)
        ];
        return $arr;
    }

}
